#include "ws_response.h"
#include "ws_constant.h"
#include "elog.h"
#include "elog_file.h"

#include "camera.pb.h"
#include "track.pb.h"
#include "system.pb.h"
#include "rgb.pb.h"
#include "track.pb.h"
#include "motor_control.pb.h"
#include "focus.pb.h"
#include "notify.pb.h"
#include "astro.pb.h"
#include "itips.pb.h"

#include <unistd.h>

int wsCommonResponse(int cmd, int module_id, int type, int code) {
    ComResponse com_res;
    com_res.set_code(code);
    std::string serialized_data;
    com_res.SerializeToString(&serialized_data);
    wsResponse(serialized_data, cmd, module_id, type);

    // log_i("cmd:%d, code:%d", cmd, code);

    return 0;
}

int wsCommonResWithInt(int cmd, int module_id, int type, int value, int code) {
    ComResWithInt com_res;
    com_res.set_value(value);
    com_res.set_code(code);
    std::string serialized_data;
    com_res.SerializeToString(&serialized_data);
    wsResponse(serialized_data, cmd, module_id, type);

    // log_i("cmd:%d, value:%d, code:%d", cmd, value, code);

    return 0;
}

int wsCommonResWithDouble(int cmd, int module_id, int type, double value, int code) {
    ComResWithDouble com_res;
    com_res.set_value(value);
    com_res.set_code(code);
    std::string serialized_data;
    com_res.SerializeToString(&serialized_data);
    wsResponse(serialized_data, cmd, module_id, type);

    // log_i("cmd:%d, value:%f, code:%d", cmd, value, code);

    return 0;
}

int wsResMotor(int cmd, int module_id, int type, int id, int code) {
    ResMotor res_motor;
    res_motor.set_id(id);
    res_motor.set_code(code);
    std::string serialized_data;
    res_motor.SerializeToString(&serialized_data);
    wsResponse(serialized_data, cmd, module_id, type);

    // log_i("cmd:%d, id:%d, code:%d", cmd, id, code);

    return 0;
}

int wsResMotorPosition(int cmd, int module_id, int type, int id, int code, double position) {
    ResMotorPosition res_motor_position;
    res_motor_position.set_id(id);
    res_motor_position.set_code(code);
    res_motor_position.set_position(position);
    std::string serialized_data;
    res_motor_position.SerializeToString(&serialized_data);
    wsResponse(serialized_data, cmd, module_id, type);

    // log_i("cmd:%d, id:%d, code:%d, position:%f", cmd, id, code, position);

    return 0;
}

int wsResCheckDarkFrame(int cmd, int module_id, int type, int code, int progress) {
    ResCheckDarkFrame res_check_dark_frame;
    
    res_check_dark_frame.set_code(code);
    res_check_dark_frame.set_progress(progress);

    std::string serialized_data;
    res_check_dark_frame.SerializeToString(&serialized_data);
    wsResponse(serialized_data, cmd, module_id, type);

    // log_i("cmd:%d, progress:%d, code:%d", cmd, progress, code);

    return 0;
}

int wsResGetAllParams(int cmd, int module_id, int type, int code, int exp_mode, int exp_index, int gain_mode, int gain_index, int ircut_value,
                        int wb_mode, int wb_ct_index, int wb_sence_index, int brightness_value, int contrast_value, int hue_value, int saturation_value, int sharpness_value, int jpg_quality_value) {

    ResGetAllParams res_get_all_params;

    CommonParam exp;
    CommonParam gain;
    CommonParam wb;
    CommonParam brightness;
    CommonParam contrast;
    CommonParam hue;
    CommonParam saturation;
    CommonParam sharpness;
    CommonParam ircut;
    CommonParam jpg_quality;

    exp.set_hasauto(true);
    exp.set_auto_mode(exp_mode);
    exp.set_id(0);
    exp.set_mode_index(0);
    exp.set_index(exp_index);

    gain.set_auto_mode(gain_mode);
    gain.set_id(1);
    gain.set_mode_index(0);
    gain.set_index(gain_index);

    wb.set_hasauto(true);
    wb.set_auto_mode(wb_mode);
    wb.set_id(2);
    wb.set_mode_index(2);
    if (wb_mode == 0) {
        wb.set_index(wb_sence_index);
    } else {
        if (wb_ct_index > 0) {
            wb.set_index(wb_ct_index);
            wb.set_mode_index(0);
        } else {
            wb.set_index(wb_sence_index);
            wb.set_mode_index(2);
        }    
    }   

    brightness.set_hasauto(false);
    brightness.set_auto_mode(0);
    brightness.set_id(3);
    brightness.set_mode_index(1);
    brightness.set_continue_value(brightness_value);

    contrast.set_hasauto(false);
    contrast.set_auto_mode(0);
    contrast.set_id(4);
    contrast.set_mode_index(1);
    contrast.set_continue_value(contrast_value);

    hue.set_hasauto(false);
    hue.set_auto_mode(0);
    hue.set_id(5);
    hue.set_mode_index(1);
    hue.set_continue_value(hue_value);

    saturation.set_hasauto(false);
    saturation.set_auto_mode(0);
    saturation.set_id(6);
    saturation.set_mode_index(1);
    saturation.set_continue_value(saturation_value);

    sharpness.set_hasauto(false);
    sharpness.set_auto_mode(0);
    sharpness.set_id(7);
    sharpness.set_mode_index(1);
    sharpness.set_continue_value(sharpness_value);

    ircut.set_hasauto(false);
    ircut.set_auto_mode(0);
    ircut.set_id(8);
    ircut.set_mode_index(0);
    ircut.set_index(ircut_value);

    if (cmd == CMD_CAMERA_TELE_GET_ALL_PARAMS) {
        gain.set_hasauto(true);

        ircut.set_hasauto(false);
        ircut.set_auto_mode(0);
        ircut.set_id(8);
        ircut.set_mode_index(0);
        ircut.set_index(ircut_value);

        jpg_quality.set_hasauto(false);
        jpg_quality.set_auto_mode(0);
        jpg_quality.set_id(9);
        jpg_quality.set_mode_index(1);
        jpg_quality.set_continue_value(jpg_quality_value);
        
    } else {
        gain.set_hasauto(false);
        wb.set_index(wb_ct_index);
        wb.set_mode_index(0);
    }


    *res_get_all_params.add_all_params() = exp;
    *res_get_all_params.add_all_params() = gain;
    *res_get_all_params.add_all_params() = wb;
    if (cmd == CMD_CAMERA_TELE_GET_ALL_PARAMS) {
        *res_get_all_params.add_all_params() = ircut;
    }
    *res_get_all_params.add_all_params() = brightness;
    *res_get_all_params.add_all_params() = contrast;
    *res_get_all_params.add_all_params() = hue;
    *res_get_all_params.add_all_params() = saturation;
    *res_get_all_params.add_all_params() = sharpness;
    if (cmd == CMD_CAMERA_TELE_GET_ALL_PARAMS) {
        *res_get_all_params.add_all_params() = jpg_quality;
    }
    
    res_get_all_params.set_code(code);

    std::string serialized_data;
    res_get_all_params.SerializeToString(&serialized_data);
    wsResponse(serialized_data, cmd, module_id, type);

    return 0;
} 

int wsResGetAllFeatureParams(int cmd, int module_id, int type, int code, int astro_binning, int astro_img_to_take, int astro_format, int burst_count, int time_lapse_interval, int time_lapse_total_time, int panorama_row,
                                int panorama_col, int astro_display_source, int burst_count_index, int burst_interval_index, WsVersion ws_version) {
    
    ResGetAllFeatureParams res_get_all_feature_parmas;                                

    CommonParam astro_binning_param;
    CommonParam astro_img_to_take_param;
    CommonParam astro_format_param;
    CommonParam burst_count_param;
    CommonParam time_lapse_interval_param;
    CommonParam time_lapse_total_time_param;
    CommonParam panorama_row_param;
    CommonParam panorama_col_param;
    CommonParam astro_display_source_param;
    CommonParam burst_interval_param;

    astro_binning_param.set_hasauto(false);
    astro_binning_param.set_auto_mode(0);
    astro_binning_param.set_id(0);
    astro_binning_param.set_mode_index(0);
    astro_binning_param.set_index(astro_binning);

    astro_img_to_take_param.set_hasauto(false);
    astro_img_to_take_param.set_auto_mode(0);
    astro_img_to_take_param.set_id(1);
    astro_img_to_take_param.set_mode_index(1);
    astro_img_to_take_param.set_continue_value(astro_img_to_take);

    astro_format_param.set_hasauto(false);
    astro_format_param.set_auto_mode(0);
    astro_format_param.set_id(2);
    astro_format_param.set_mode_index(0);
    astro_format_param.set_index(astro_format);

    burst_count_param.set_hasauto(false);
    burst_count_param.set_auto_mode(0);
    burst_count_param.set_id(3);
    if (ws_version.isGreaterThan(1, 1))   
        burst_count_param.set_mode_index(0);
    else
        burst_count_param.set_mode_index(1);
    burst_count_param.set_continue_value(burst_count);
    burst_count_param.set_index(burst_count_index);

    time_lapse_interval_param.set_hasauto(false);
    time_lapse_interval_param.set_auto_mode(0);
    time_lapse_interval_param.set_id(4);
    time_lapse_interval_param.set_mode_index(0);
    time_lapse_interval_param.set_index(time_lapse_interval);

    time_lapse_total_time_param.set_hasauto(false);
    time_lapse_total_time_param.set_auto_mode(0);
    time_lapse_total_time_param.set_id(5);
    time_lapse_total_time_param.set_mode_index(0);
    time_lapse_total_time_param.set_index(time_lapse_total_time);

    panorama_row_param.set_hasauto(false);
    panorama_row_param.set_auto_mode(0);
    panorama_row_param.set_id(6);
    panorama_row_param.set_mode_index(1);
    panorama_row_param.set_continue_value(panorama_row);

    panorama_col_param.set_hasauto(false);
    panorama_col_param.set_auto_mode(0);
    panorama_col_param.set_id(7);
    panorama_col_param.set_mode_index(1);
    panorama_col_param.set_continue_value(panorama_col);

    astro_display_source_param.set_hasauto(false);
    astro_display_source_param.set_auto_mode(0);
    astro_display_source_param.set_id(8);
    astro_display_source_param.set_mode_index(0);
    astro_display_source_param.set_index(astro_display_source);

    burst_interval_param.set_hasauto(false);
    burst_interval_param.set_auto_mode(1);
    burst_interval_param.set_id(9);
    burst_interval_param.set_mode_index(0);
    burst_interval_param.set_continue_value(burst_count);
    burst_interval_param.set_index(burst_interval_index);

    *res_get_all_feature_parmas.add_all_feature_params() = astro_binning_param;
    *res_get_all_feature_parmas.add_all_feature_params() = astro_img_to_take_param;
    *res_get_all_feature_parmas.add_all_feature_params() = astro_format_param;
    *res_get_all_feature_parmas.add_all_feature_params() = burst_count_param;
    *res_get_all_feature_parmas.add_all_feature_params() = time_lapse_interval_param;
    *res_get_all_feature_parmas.add_all_feature_params() = time_lapse_total_time_param;
    *res_get_all_feature_parmas.add_all_feature_params() = panorama_row_param;
    *res_get_all_feature_parmas.add_all_feature_params() = panorama_col_param;
    *res_get_all_feature_parmas.add_all_feature_params() = astro_display_source_param;
    *res_get_all_feature_parmas.add_all_feature_params() = burst_interval_param;

    res_get_all_feature_parmas.set_code(code);

    std::string serialized_data;
    res_get_all_feature_parmas.SerializeToString(&serialized_data);
    wsResponse(serialized_data, cmd, module_id, type);

    // log_i("cmd:%d, code:%d, astro_binning:%d, astro_img_to_take:%d, astro_format:%d, burst_count:%d, time_lapse_interval:%d, time_lapse_total_time:%d, panorama_row:%d, panorama_col:%d, astro_display_source:%d", 
        // cmd, code, astro_binning, astro_img_to_take, astro_format, burst_count, time_lapse_interval, time_lapse_total_time, panorama_row, panorama_col, astro_display_source);

    return 0;

}

/*------------------------------------------------------------------通知消息--------------------------------------------------------------------------*/
int wsResNotifyPictureMatching(int cmd, int module_id, int type, int code, int x, int y, int width, int height, double value) {
    ResNotifyPictureMatching res_notify_picutre_matching;

    res_notify_picutre_matching.set_code(code);
    res_notify_picutre_matching.set_x(x);
    res_notify_picutre_matching.set_y(y);
    res_notify_picutre_matching.set_width(width);
    res_notify_picutre_matching.set_height(height);

    std::string serialized_data;
    res_notify_picutre_matching.SerializeToString(&serialized_data);
    wsResponse(serialized_data, cmd, module_id, type);

    // log_i("cmd:%d, code:%d, x:%d, y:%d, width:%d, height:%d, value:%f", cmd, code, x, y, width, height, value);

    return 0;
}

int wsResNotifySDcardInfo(int cmd, int module_id, int type, int code, int available_size, int total_size) {
    ResNotifySDcardInfo res_notify_sdcard_info;

    res_notify_sdcard_info.set_code(code);
    res_notify_sdcard_info.set_available_size(available_size);
    res_notify_sdcard_info.set_total_size(total_size);

    std::string serialized_data;
    res_notify_sdcard_info.SerializeToString(&serialized_data);
    wsResponse(serialized_data, cmd, module_id, type);

    // log_i("cmd:%d, code:%d, available_size:%d, total_size:%d", cmd, code, available_size, total_size);

    return 0;
}

int wsResNotifyRecordTime(int cmd, int module_id, int type, int time) {
    ResNotifyRecordTime res_notify_record_time;

    res_notify_record_time.set_record_time(time);
    
    std::string serialized_data;
    res_notify_record_time.SerializeToString(&serialized_data);
    wsResponse(serialized_data, cmd, module_id, type);

    // log_i("cmd:%d, time:%d", cmd, time);

    return 0;
}

int wsResNotifyTimelapseOutTime(int cmd, int module_id, int type, int interval, int out_time, int total_time) {
    ResNotifyTimeLapseOutTime res_notify_timelapse_outtime;

    res_notify_timelapse_outtime.set_interval(interval);
    res_notify_timelapse_outtime.set_out_time(out_time);
    res_notify_timelapse_outtime.set_total_time(total_time);

    std::string serialized_data;
    res_notify_timelapse_outtime.SerializeToString(&serialized_data);
    wsResponse(serialized_data, cmd, module_id, type);

    // log_i("cmd:%d, interval:%d, out_time:%d, total_time:%d", cmd, interval, out_time, total_time);

    return 0;
}   

int wsResNotifyParam(int cmd, int module_id, int type, bool has_auto, int auto_mode, int id, int mode_index, int index, double continue_value) {
    ResNotifyParam res_notify_param;
    CommonParam notify_common_param;

    notify_common_param.set_hasauto(has_auto);
    notify_common_param.set_auto_mode(auto_mode);
    notify_common_param.set_id(id);
    notify_common_param.set_mode_index(mode_index);
    notify_common_param.set_index(index);
    notify_common_param.set_continue_value(continue_value);

    *res_notify_param.add_param() = notify_common_param;

    std::string serialized_data;
    res_notify_param.SerializeToString(&serialized_data);
    usleep(10 * 1000);
    wsResponse(serialized_data, cmd, module_id, type);

    // log_i("cmd:%d, has_auto:%d, auto_mode:%d, id:%d, mode_index:%d, index:%d, continue_value:%f", cmd, has_auto, auto_mode, id, mode_index, index, continue_value);

    return 0;
}

int wsResNotifyCamFunctionState(int cmd, int module_id, int type, int function_id ,int state) {
    ResNotifyCamFunctionState res_notify_cam_function_state;

    res_notify_cam_function_state.set_function_id(function_id);
    res_notify_cam_function_state.set_state((OperationState)state);

    std::string serialized_data;
    res_notify_cam_function_state.SerializeToString(&serialized_data);
    usleep(10 * 1000);
    wsResponse(serialized_data, cmd, module_id, type);

    // log_i("cmd:%d, function_id:%d, state:%d", cmd, function_id, state);

    return 0;

}

int wsResNotifySentryModeState(int cmd, int module_id, int type, int state) {
    ResNotifyStateSentryMode res_state;

    res_state.set_state((SentryModeState)state);

    std::string serialized_data;
    res_state.SerializeToString(&serialized_data);
    usleep(10 * 1000);
    wsResponse(serialized_data, cmd, module_id, type);

    // log_i("cmd:%d, function_id:%d, state:%d", cmd, function_id, state);

    return 0;
}

int wsResNotifyOperationState(int cmd, int module_id, int type, int state) {
    if (state < OPERATION_STATE_IDLE || state > OPERATION_STATE_STOPPED)
        return -1;

    ResNotifyOperationState res_notify_operation_state;
    
    res_notify_operation_state.set_state((OperationState)state);

    std::string serialized_data;
    res_notify_operation_state.SerializeToString(&serialized_data);
    usleep(10 * 1000);
    wsResponse(serialized_data, cmd, module_id, type);

    // log_i("cmd:%d, state:%d", cmd, state);

    return 0;
}

int wsResNotifyAstroCalibrationState(int cmd, int module_id, int type, int state, int plate_solving_times) {
    if (state < ASTRO_STATE_IDLE || state > ASTRO_STATE_PLATE_SOLVING)
        return -1;

    ResNotifyStateAstroCalibration res_notify_state_astro_calibration;

    res_notify_state_astro_calibration.set_state((AstroState)state);
    res_notify_state_astro_calibration.set_plate_solving_times(plate_solving_times);

    std::string serialized_data;
    res_notify_state_astro_calibration.SerializeToString(&serialized_data);
    usleep(10 * 1000);
    wsResponse(serialized_data, cmd, module_id, type);

    // log_i("cmd:%d, state:%d, plate_solving_times:%d", cmd, state, plate_solving_times);

    return 0;
}

int wsResNotifyAstroGotoState(int cmd, int module_id, int type, int state) {
    if (state < ASTRO_STATE_IDLE || state > ASTRO_STATE_PLATE_SOLVING)
        return -1;

    ResNotifyStateAstroGoto res_notify_state_astro_goto;

    res_notify_state_astro_goto.set_state((AstroState)state);

    std::string serialized_data;
    res_notify_state_astro_goto.SerializeToString(&serialized_data);
    usleep(10 * 1000);
    wsResponse(serialized_data, cmd, module_id, type);

    // log_i("cmd:%d, state:%d", cmd, state);

    return 0;
}

int wsResNotifyAstroTrackingState(int cmd, int module_id, int type, int state, std::string& target_name) {
    if (state < OPERATION_STATE_IDLE || state > OPERATION_STATE_STOPPED)
        return -1;

    ResNotifyStateAstroTracking res_notify_astro_tracking_state;
    
    res_notify_astro_tracking_state.set_state((OperationState)state);
    res_notify_astro_tracking_state.set_target_name(target_name);

    std::string serialized_data;
    res_notify_astro_tracking_state.SerializeToString(&serialized_data);
    usleep(10 * 1000);
    wsResponse(serialized_data, cmd, module_id, type);

    // log_i("cmd:%d, state:%d, target_name:%s", cmd, state, target_name.c_str());

    return 0;
}

int wsResNotifyAstroSpecialTrackingState(int cmd, int module_id, int type, int state, std::string& target_name, int index) {
    if (state < OPERATION_STATE_IDLE || state > OPERATION_STATE_STOPPED)
        return -1;

    ResNotifyStateAstroTrackingSpecial res_notify_astro_tracking_state_special;
    
    res_notify_astro_tracking_state_special.set_state((OperationState)state);
    res_notify_astro_tracking_state_special.set_target_name(target_name);
    res_notify_astro_tracking_state_special.set_index(index);

    std::string serialized_data;
    res_notify_astro_tracking_state_special.SerializeToString(&serialized_data);
    usleep(10 * 1000);
    wsResponse(serialized_data, cmd, module_id, type);

    // log_i("cmd:%d, state:%d, target_name:%s, index:%d", cmd, state, target_name.c_str(), index);

    return 0;
}

int wsResNotifyProgressCaptureRawDark(int cmd, int module_id, int type, int progress, int remaining_time) {
    ResNotifyProgressCaptureRawDark res_notify_progress_capture_raw_dark;

    res_notify_progress_capture_raw_dark.set_progress(progress);
    res_notify_progress_capture_raw_dark.set_remaining_time(remaining_time);

    std::string serialized_data;
    res_notify_progress_capture_raw_dark.SerializeToString(&serialized_data);
    usleep(10 * 1000);
    wsResponse(serialized_data, cmd, module_id, type);

    // log_i("cmd:%d, progress:%d, remaining_time:%d", cmd, progress, remaining_time);

    return 0;
}

int wsResNotifyProgressCaptureRawLiveStacking(int cmd, int module_id, int type, int total_count, int update_count_type, int current_count, int stacked_count, int exp_index, int gain_index, std::string& target_name) {
    ResNotifyProgressCaptureRawLiveStacking res_notify_progress_capture_raw_live_stacking;

    res_notify_progress_capture_raw_live_stacking.set_total_count(total_count);
    res_notify_progress_capture_raw_live_stacking.set_update_count_type(update_count_type);
    res_notify_progress_capture_raw_live_stacking.set_current_count(current_count);
    res_notify_progress_capture_raw_live_stacking.set_stacked_count(stacked_count);
    res_notify_progress_capture_raw_live_stacking.set_exp_index(exp_index);
    res_notify_progress_capture_raw_live_stacking.set_gain_index(gain_index);
    res_notify_progress_capture_raw_live_stacking.set_target_name(target_name);

    std::string serialized_data;
    res_notify_progress_capture_raw_live_stacking.SerializeToString(&serialized_data);
    usleep(10 * 1000);
    wsResponse(serialized_data, cmd, module_id, type);

    // log_i("cmd:%d, total_count:%d, update_count_type:%d, current_count:%d, stacked_count:%d, exp_index:%d, gain_index:%d, target_name:%s", cmd, total_count, update_count_type, current_count, stacked_count, exp_index, gain_index, target_name.c_str());

    return 0;
}

int wsResNotifyBurstProgress(int cmd, int module_id, int type, int total_count, int completed_count) {
    ResNotifyBurstProgress res_notify_burst_progress;
    
    res_notify_burst_progress.set_total_count(total_count);
    res_notify_burst_progress.set_completed_count(completed_count);

    std::string serialized_data;
    res_notify_burst_progress.SerializeToString(&serialized_data);
    wsResponse(serialized_data, cmd, module_id, type);

    // log_i("cmd:%d, total_count:%d, completed_count:%d", cmd, total_count, completed_count);

    return 0;
}

int wsResNotifyPanoramaProgress(int cmd, int module_id, int type, int total_count, int completed_count) {
    ResNotifyPanoramaProgress res_notify_panorama_progress;
    
    res_notify_panorama_progress.set_total_count(total_count);
    res_notify_panorama_progress.set_completed_count(completed_count);

    std::string serialized_data;
    res_notify_panorama_progress.SerializeToString(&serialized_data);
    wsResponse(serialized_data, cmd, module_id, type);

    // log_i("cmd:%d, total_count:%d, completed_count:%d", cmd, total_count, completed_count);

    return 0;
}

int wsResNotifyRgbState(int cmd, int module_id, int type, int state) {
    ResNotifyRgbState res_notify_rgb_state;

    res_notify_rgb_state.set_state(state);

    std::string serialized_data;
    res_notify_rgb_state.SerializeToString(&serialized_data);
    wsResponse(serialized_data, cmd, module_id, type);

    // log_i("cmd:%d, state:%d", cmd, state);

    return 0;
}

int wsResNotifyPowerIndState(int cmd, int module_id, int type, int state) {
    ResNotifyPowerIndState res_notify_power_ind_state;

    res_notify_power_ind_state.set_state(state);

    std::string serialized_data;
    res_notify_power_ind_state.SerializeToString(&serialized_data);
    wsResponse(serialized_data, cmd, module_id, type);

    // log_i("cmd:%d, state:%d", cmd, state);

    return 0;
}

int wsResNotifyHostSlaveMode(int cmd, int module_id, int type, int mode, const std::string& client_id, bool lock_master) {
    ResNotifyHostSlaveMode res_notify_host_slave_mode;

    res_notify_host_slave_mode.set_mode(mode);
    res_notify_host_slave_mode.set_lock(lock_master);

    std::string serialized_data;
    res_notify_host_slave_mode.SerializeToString(&serialized_data);
    // wsResponse(serialized_data, cmd, module_id, type);
    wsResponseByClientId(serialized_data, cmd, module_id, type, client_id);

    // log_i("cmd:%d, mode:%d, client_id:%s", cmd, mode, client_id.c_str());

    return 0;
}

int wsResNotifyMTPState(int cmd, int module_id, int type,int mode) {
    ResNotifyMTPState res_notify_mtp_state;

    res_notify_mtp_state.set_mode(mode);

    std::string serialized_data;
    res_notify_mtp_state.SerializeToString(&serialized_data);
    wsResponse(serialized_data, cmd, module_id, type);

    // log_i("cmd:%d, mode:%d", cmd, mode);

    return 0;
}

int wsResNotifyTrackResult(int cmd, int module_id, int type, int x, int y, int w, int h) {
    ResNotifyTrackResult res_notify_track_result;

    res_notify_track_result.set_x(x);
    res_notify_track_result.set_y(y);
    res_notify_track_result.set_w(w);
    res_notify_track_result.set_h(h);

    std::string serialized_data;
    res_notify_track_result.SerializeToString(&serialized_data);
    wsResponse(serialized_data, cmd, module_id, type);

    // log_i("cmd:%d, x:%d, y:%d, w:%d, h:%d", cmd, x, y, w, h);

    return 0;
}

int wsResNotifyCPUMode(int cmd, int module_id, int type,int mode) {
    ResNotifyCPUMode res_notify_cpu_mode;

    res_notify_cpu_mode.set_mode(mode);

    std::string serialized_data;
    res_notify_cpu_mode.SerializeToString(&serialized_data);
    wsResponse(serialized_data, cmd, module_id, type);

    // log_i("cmd:%d, mode:%d", cmd, mode);

    return 0;
}

int wsResNotifyPowerOff(int cmd, int module_id, int type) {
    ResNotifyPowerOff res_notify_power_off;
    // log_i("notify power off");
    std::string serialized_data;
    res_notify_power_off.SerializeToString(&serialized_data);
    wsResponse(serialized_data, cmd, module_id, type);

    // log_i("cmd:%d", cmd);

    return 0;
}

int wsResITipsGet(int cmd, int module_id, int type, int code, int mode, const std::string& itips_code) {
    ResITipsGet res_itips_get;

    res_itips_get.set_code(code);
    res_itips_get.set_mode(mode);
    res_itips_get.set_itips_code(itips_code);

    std::string serialized_data;
    res_itips_get.SerializeToString(&serialized_data);
    wsResponse(serialized_data, cmd, module_id, type);

    // log_i("cmd:%d, mode:%d, itips_code:%s", cmd, mode, itips_code.c_str());

    return 0;
}

int wsNotifyAlbumUpdate(int cmd, int module_id, int type, int media_type) {
    ResNotifyAlbumUpdate res_notify_album_update;

    res_notify_album_update.set_media_type(media_type);

    std::string serialized_data;
    res_notify_album_update.SerializeToString(&serialized_data);
    wsResponse(serialized_data, cmd, module_id, type);

    return 0;
}